package com.whccb.apps.office.document.event.receive.system;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener;
import com.actionsoft.bpms.commons.formfile.model.delegate.FormFile;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.fs.DCContext;
import com.actionsoft.sdk.local.SDK;

public class TestA extends ExecuteListener {

	public String getDescription() {
		return "测试";
	}

	public String getProvider() {
		return "ActionSoft";
	}

	public String getVersion() {
		return "AWS 6.0";
	}

	@Override
	public void execute(ProcessExecutionContext pec) throws Exception {
		BO bo = SDK.getBOAPI().getByProcess("BO_EU_FJCS",
				pec.getProcessInstance().getId());
		if (bo != null) {
			DCContext fjdc = null;
			List<FormFile> fjFormFileList = SDK.getBOAPI().getFiles(bo.getId(),
					"AAA");
			if (fjFormFileList != null && !fjFormFileList.isEmpty()
					&& fjFormFileList.size() > 0) {
				FormFile fjFormFile = fjFormFileList.get(0);
				fjdc = SDK.getBOAPI().getFileDCContext(fjFormFile);
			}

			// 调用App
			String sourceAppId = "com.actionsoft.apps.poi.converter";
			// aslp服务地址
			String aslp = "aslp://com.actionsoft.apps.poi.converter/fileToHTML";
			// 参数定义列表
			Map params = new HashMap<String, Object>();
			// 当前用户sid,必填
			params.put("sid", pec.getUserContext().getSessionId());
			// 从DC处理要上传的文件，一个指定的DCContext.toJson()参数,必填
			params.put("dcContext", fjdc.toJson());
			// 值为true时,在否访问文档时才进行转换, false时马上转换为html，默认值为true。,非必填
			params.put("lazyConvert", false);
			// 文件转换为HTML
			ResponseObject ro = SDK.getAppAPI().callASLP(
					SDK.getAppAPI().getAppContext(sourceAppId), aslp, params);
			System.out.println("ro====" + ro);
		}

	}

}
